package com.netCross.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class SettingActivity extends AppCompatActivity {
    SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        fillTextView();
//        onBackPressed();
    }

    @Override
   public void onBackPressed(){
       super.onBackPressed();
    }


    void fillTextView(){
         sp = getSharedPreferences("config", MODE_PRIVATE);
         SharedPreferences.Editor editor = sp.edit();
         String getUserName = sp.getString("userName","");
        String getPassword = sp.getString("password","");
        String getIp = sp.getString("ip","");
        String getAndroidId = sp.getString("androidId","");
        String getRememberMe = sp.getString("rememberMe","");

        TextView tv1 = findViewById(R.id.showUserNameTextView);
        tv1.setText(getUserName);
        this.setTitle("设置");
        TextView tv2 = findViewById(R.id.textView11);
        if (getUserName.equals("user1")){
          String  message= "该内容只有超级用户可见";
          tv2.setText(message);
            }
        else {
            tv2.setVisibility(View.INVISIBLE);
        }

    }

        public void logoutButtonOnCLick(View view) {
             sp = getSharedPreferences("config",MODE_PRIVATE);
             SharedPreferences.Editor  editor = sp.edit();
             editor.putString("userName","");
             editor.putString("password","");
             editor.putString("ip","");
             editor.putString("androidId","");
             editor.putString("rememberMe", "False");
             editor.commit();
         Intent intent = new Intent(this,MainActivity.class);
         this.startActivity(intent);
        }

}